package fun.easycode.webterminal.adapter.api;

import fun.easycode.webterminal.common.contract.PageDTO;
import fun.easycode.webterminal.common.contract.R;
import fun.easycode.webterminal.service.ProxyTransformService;
import fun.easycode.webterminal.service.cmd.ProxyTransformPageQry;
import fun.easycode.webterminal.service.cmd.ProxyTransformSaveCmd;
import fun.easycode.webterminal.service.dto.ProxyTransformDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

@Tag(name = "代理转换")
@RestController
@RequestMapping("/api/proxy-transform")
public class ProxyTransformApi {

    private final ProxyTransformService proxyTransformService;

    public ProxyTransformApi(ProxyTransformService proxyTransformService) {
        this.proxyTransformService = proxyTransformService;
    }

    @Operation(summary = "删除代理转换")
    @PostMapping("/delete")
    public R<String> delete(@RequestParam String id) {
        return proxyTransformService.delete(id);
    }

    @Operation(summary = "根据id查询代理转换")
    @GetMapping("/get-by-id")
    public R<ProxyTransformDTO> getById(@RequestParam String id){
        return proxyTransformService.getById(id);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询代理转换")
    public R<PageDTO<ProxyTransformDTO>> page(ProxyTransformPageQry cmd) {
        return proxyTransformService.page(cmd);
    }

    @PostMapping("/save")
    @Operation(summary = "保存代理转换(新建/编辑)")
    public R<String> save(@RequestBody ProxyTransformSaveCmd cmd) {
        return proxyTransformService.save(cmd);
    }

    @PostMapping("/start")
    @Operation(summary = "启动代理转换")
    public R<String> start(@RequestParam String id) {
        return proxyTransformService.start(id);
    }

    @PostMapping("/stop")
    @Operation(summary = "停止代理转换")
    public R<String> stop(@RequestParam String id) {
        return proxyTransformService.stop(id);
    }
}
